home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / science / sm32a.zip / LIBRARY / PSOLVE.LI < prev    next >
Text File  |  1994-09-21  |  827b  |  14 lines

  1. #    psolve() is polynomial solver
  2. #    e.g. psolve(x^2+5*x+6, x) gives [-2, -3]
  3.  
  4. psolve(y_, x1_) := if(order(y,x1) == 1,
  5.     -coef(y,x1,0)/coef(y,x1,1) )
  6. psolve(y_, x2_) := if(order(y,x2) == 2,
  7.     [(-coef(y,x2,1)+sqrt(coef(y,x2,1)^2-4*coef(y,x2,2)*coef(y,x2,0)))/(2*coef(y,x2,2)),
  8.      (-coef(y,x2,1)-sqrt(coef(y,x2,1)^2-4*coef(y,x2,2)*coef(y,x2,0)))/(2*coef(y,x2,2))])
  9. psolve(y_, x4_) := if(order(y,x4) == 4 and coef(y,x4,3) ==0 and coef(y,x4,1)==0,
  10.     [sqrt((-coef(y,x4,2)+sqrt(coef(y,x4,2)^2-4*coef(y,x4,4)*coef(y,x4,0)))/(2*coef(y,x4,4))),
  11.     -sqrt((-coef(y,x4,2)+sqrt(coef(y,x4,2)^2-4*coef(y,x4,4)*coef(y,x4,0)))/(2*coef(y,x4,4))),
  12.      sqrt((-coef(y,x4,2)-sqrt(coef(y,x4,2)^2-4*coef(y,x4,4)*coef(y,x4,0)))/(2*coef(y,x4,4))),
  13.      -sqrt((-coef(y,x4,2)-sqrt(coef(y,x4,2)^2-4*coef(y,x4,4)*coef(y,x4,0)))/(2*coef(y,x4,4))) ])
  14.